# -*- coding:utf-8 -*-
# Author: zwx973256
# Date: 2022/05/31 - 19:35:40

import sys
import os
import json

def genPartsInfoJSON(folder_list,output_json_path):
    '''
    #根据部件信息,生成字典至json文件中
    '''
    if len(folder_list) != 0:
        data_dict = {}
        for folder_str in folder_list:
            data_dict[folder_str] = "innerkits/ohos-arm64/" + folder_str
        output_json_path = os.path.join(output_json_path, "kits_modules_info.json")
        json_str = json.dumps(data_dict, indent=2)
        with open(output_json_path, "w") as json_file:
            json_file.write(json_str)
    else:
        print("Failed to obtain component information")

def getPartsJson(path):
    '''
    #获取out/rk3568/innerkits/ohos-arm内部接口文件夹名称列表
    '''
    if os.path.exists(path):
        folder_list = os.listdir(path)
    else:
        print("The folder does not exist")
    return folder_list

if __name__ == "__main__":
    """
    if len(sys.argv) == 2:
        part_info_path = sys.argv[1]
        print(part_info_path)
        output_json_path = sys.argv[2]
        print(output_json_path)
    else:
        print("The input parameter is incorrect")
    """
    part_info_path = "/home/cjj/open/out/rk3568/innerkits/ohos-arm64"
    output_json_path = "/home/cjj/open/out/rk3568/packages/phone/innerkits/ohos-arm64"
    os.system("mkdir -p " + output_json_path)
    print("part_info_path=",part_info_path)
    print("output_json_path=", output_json_path)
    folder_list = getPartsJson(part_info_path)
    genPartsInfoJSON(folder_list,output_json_path)

